import Qlearning as RL
import config_ql as qc

class QLAgent:
    def __init__(self):
        self.ql = RL.QLearning(qc.STATE_NUMBER, qc.ACTION_NUMBER)

    def choose_action(self, state_results, epsilon=None):
        state_idx = qc.state_encode(state_results)
        action_id = self.ql.choose_action(state_idx, epsilon=epsilon)
        select_num = qc.action_encode(action_id)
        return action_id, select_num

    def learn(self, state_results, state_results_next, action_idx, utility):
        state_idx = qc.state_encode(state_results)
        state_next_idx = qc.state_encode(state_results_next)
        self.ql.learn(state_idx, state_next_idx, action_idx, utility)

    def reset(self):
        self.ql.reset()